package com.demo.jpa.util;

import lombok.Builder;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.SpringApplication;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Author:liaoyoule
 * @Description
 * @Date: Created in 14:19 2018/6/2
 * @Modifyied By:
 */
@Log4j2
@Builder
public class ZoneStartHelper {
    private String[] args;
    private Object sources;


    public void start() throws UnknownHostException {
        Environment env = new SpringApplication(sources).run(args).getEnvironment();
        String protocol = "http";
        String serverPort = env.getProperty("server.port");
        String contentPath = env.getProperty("server.context-path");
        if (null == contentPath) {
            contentPath = "";
        }
        log.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\t{}://localhost:{}{}\n\t" +
                        "External: \t{}://{}:{}{}\n\t" +
                        "Swagger: \t{}://{}:{}{}{}\n\t" +
                        "Profile(s): \t{}\n----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                protocol,
                serverPort,
                contentPath,
                protocol,
                InetAddress.getLocalHost().getHostAddress(),
                serverPort,
                contentPath,
                protocol,
                InetAddress.getLocalHost().getHostAddress(),
                serverPort,
                contentPath,
                "/swagger-ui.html",
                env.getActiveProfiles());
    }


}
